﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DungeonMaker
{
    
    class CellCreator
    {
        public GUI g = new GUI();
        Entity cruser;
        Position cPos = new Position();
        public List<Entity> walls = new List<Entity>();

        public CellCreator() 
        {
            cruser = new Entity(g.GetCharcode(176),cPos);
            Main();
            //MakeBase(Console.BufferWidth- 10,Console.BufferHeight-10);

        }


        public void Main() 
        {
            Position oldpos;
            bool squaremode = false;
            bool loop = true;
            ConsoleKeyInfo ckey = Console.ReadKey(true);
            while (loop)
            {
                g.WriteTextAt("Main Loop", g.centerText("main loop", 3));
                if (squaremode)
                {
                    squaremode = Squaremode();
                }
                else
                {
                   ckey = Console.ReadKey(true);
                }

                if (ckey.Key == ConsoleKey.Q) 
                {
                    squaremode = true;
                }
            }
        }
        public bool Squaremode() 
        {
            var a = new MakeSquare();
            a.sPos = cPos;
            int width = 3;
            int height = 3;
            
            Console.Clear();

            g.WriteTextAt("Enter size", g.centerText("enter size"));
            a.MakeBase(width, height);
            var ckey = Console.ReadKey(true);
            if (ckey.Key == ConsoleKey.D)
            {
                width++;
            }
            else if (ckey.Key == ConsoleKey.A)
            {
                if (width > 1)
                    width--;
            }
            else if (ckey.Key == ConsoleKey.W)
            {
                if (height > 1)
                    height--;

            }
            else if (ckey.Key == ConsoleKey.S)
            {
                height++;
            }
            a.MakeBase(width, height);
            if (ckey.Key == ConsoleKey.Escape)
            {
                return true;
            }
            else 
            {
                return false;
            }
        }

        public void Clear(Position pos, int width = 1, int height = 1)
        {
            int curTop = Console.CursorTop;
            int curLeft = Console.CursorLeft;
            var c = Encoding.GetEncoding(437).GetChars(new byte[] { 0 })[0];
            for (; height > 0; )
            {
                Console.SetCursorPosition(pos.X, pos.Y + --height);
                Console.Write(new string(' ', width));
                Console.Write(c);

            }
            Console.SetCursorPosition(curLeft, curTop);
        }
    }
}
